<?php 
$result = BankAccounts::model()->getAccount(Yii::app()->user->userID);
$states = USStates::model()->getAllStates();

foreach ($result as $record) {
	$account = $record;
}
preg_match('/^([0-9]+)([0-9]{4})$/', $account['routing_number'], $matches);
$account['routing_number'] = preg_replace('/[0-9]/', '*', $matches[1]).$matches[2];

//Yii::app()->getSecurityManager()->setEncryptionKey('12345678');
//$lastFourDigits = Yii::app()->getSecurityManager()->decrypt(BankAccounts::model()->getLastFourDigits(Yii::app()->user->userID));
$lastFourDigits = BankAccounts::model()->getLastFourDigits(Yii::app()->user->userID);
$account['account_number'] = '******'.$lastFourDigits;
?>

<?php $bank_form = $this->beginWidget('CActiveForm', array(
		'id'=>'bank-form',
		'enableClientValidation'=>true,
	//	'enableAjaxValidation'=>true,
		));
?>

	<?php echo $bank_form->error($bank_model, "bank_name") ?>
	<?php echo $bank_form->error($bank_model, "branch_name"); ?>
	<?php echo $bank_form->error($bank_model, "city"); ?>
	<?php echo $bank_form->error($bank_model, "zip"); ?>
	<?php echo $bank_form->error($bank_model, "routing_number"); ?>
	<?php echo $bank_form->error($bank_model, "accounting_number"); ?>
<div id="payment-left">
<div class="payment-subhead2">Let us draft your account ...</div>

<div id="left-deatils">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th width="64">Bank Name</th>
    <td width="345"><div class="payment-box5">
    	<?php echo $bank_form->textField($bank_model, 'bank_name', array('value'=>$account['bank_name'])); ?>
    </div></td>
  </tr>
  <tr>
    <th>Branch</th>
    <td><div class="payment-box5">
    	<?php echo $bank_form->textField($bank_model, 'branch_name', array('value'=>$account['branch_name'])); ?>
    </div></td>
  </tr>
  <tr>
    <td colspan="2">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th width="64">City</th>
          <td width="118"><div class="payment-box2">
          	<?php echo $bank_form->textField($bank_model, 'city', array('value'=>$account['city'])); ?>
          </div></td>
          <th width="29" style="padding-right:4px; padding-left:2px;">State</th>
          <td width="69">
          <div class="state"><select name="BankAccounts[state]">
          <?php foreach ($states as $state) { 
          	if ($account['state'] == $state->abbreviation_name)
          		$selected = "SELECTED";
          	else
          		$selected = '';
          	echo '<option '.$selected.'>'.$state->abbreviation_name.'</option>';
          } ?>
          </select></div>
          </td>
          <th width="21">Zip</th>
          <td><div class="payment-box3">
          	<?php echo $bank_form->textField($bank_model, 'zip', array('value'=>$account['zip'])); ?>
          </div></td>
        </tr>
      </table>
    </td>
    </tr>
  <tr>
    <th>Routing #</th>
    <td><div class="payment-box5">
    	<?php echo $bank_form->textField($bank_model, 'routing_number', array('value'=>$account['routing_number'])); ?>
    </div></td>
  </tr>
  <tr>
    <th>Account #</th>
    <td><div class="payment-box5">
    	<?php echo $bank_form->textField($bank_model, 'account_number', array('value'=>$account['account_number'])); ?>
    </div></td>
  </tr>
</table>
</div><!-- End Left Details -->

<div id="cheque"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/cheque.gif" alt="" /></div>
<div class="payment-submit">
<?php echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/submit.jpg', array(
										'ajax'=>array(				
											'type'=>'POST',
											'url'=>CController::createUrl('admin/payment'),
											'success'=>'updateStatus',
											'dataType'=>'json',
										),
									)
								); 
?>
</div>
</div><!-- End Payment Left -->

<?php $this->endWidget();?>